//
//  SZCalendarCell.m
//  SZCalendarPicker
//
//  Created by Stephen Zhuang on 14/12/1.
//  Copyright (c) 2014年 Stephen Zhuang. All rights reserved.
//

#import "SZCalendarCell.h"

#define cellWidth 36
#define cellHeitht 30
#define cellFout 12

@implementation SZCalendarCell

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        backView = [[UIView alloc] initWithFrame:(CGRect){1,1,WIDTH(self)-2,HEIGHT(self)-2}];
        [backView setBackgroundColor:[UIColor whiteColor]];
        [self addSubview:backView];

        _dateLabel = [[UILabel alloc] init];
        [_dateLabel setTextAlignment:NSTextAlignmentCenter];
        [_dateLabel setFont:[UIFont systemFontOfSize:12]];
        [_dateLabel setBackgroundColor:[UIColor clearColor]];
        [backView addSubview:_dateLabel];
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refeshBackViewColor:) name:kRefeshCalendarBackColor object:nil];
    }
    return self;
}

- (void)refeshBackViewColor:(NSNotification *)noti
{
    if (noti.object ==  self) {
        //
        [backView setBackgroundColor:[UIColor colorWithHexString:@"#cccccc"]];
    }else{
        [backView setBackgroundColor:[UIColor whiteColor]];
    }
}

- (UIImageView *)starImageView
{
    if (!_starImageView) {
        _starImageView = [[UIImageView alloc] initWithFrame:(CGRect){12,16,11,12}];
        [_starImageView setImage:[UIImage imageNamed:@"star_schedule@2X.png"]];
        [backView addSubview:_starImageView];
        [_starImageView setHidden:YES];
    }
    return _starImageView;
}
- (void)reloadCell:(NSIndexPath *)indexPath haveStar:(BOOL)haveStar
{
    if (indexPath.section == 0) {
        //
        [_dateLabel setFrame:(CGRect){0,0,WIDTH(backView),HEIGHT(backView)}];
    }else if (indexPath.section == 1){
        [_dateLabel setFrame:(CGRect){0,0,WIDTH(backView),HEIGHT(backView)/2}];
    }
    self.starImageView.hidden = haveStar;
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            //
            [backView setFrame:(CGRect){1,1,WIDTH(self)-2,HEIGHT(self)-2}];
        }else{
            [backView setFrame:(CGRect){0,1,WIDTH(self)-1,HEIGHT(self)-2}];
        }
    }else{
        if (indexPath.row == 0 || indexPath.row == 7 || indexPath.row == 14 || indexPath.row == 21 || indexPath.row == 28 || indexPath.row == 35) {
            //
            [backView setFrame:(CGRect){1,0,WIDTH(self)-2,HEIGHT(self)-1}];
        }else{
            [backView setFrame:(CGRect){0,0,WIDTH(self)-1,HEIGHT(self)-1}];
        }
    }
}
@end
